package com.xoa.plugin.workflow.workflowservice.imlp.lnsfplugin;

import com.xoa.dev.efficiency.model.FlowAbilityMonitor;
import com.xoa.model.users.Users;
import com.xoa.plugin.workflow.workflowservice.WorkFlowService;
import com.xoa.util.ToJson;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class Major_5 implements WorkFlowService {
    @Override
    public ToJson run(HttpServletRequest request) {
        LnsfUtil lnsfUtil=LnsfUtil.init();
        Users user=lnsfUtil.getUser(request);
        String prcsId=request.getParameter("prcsId");
        String runId=request.getParameter("runId");
        String flowId=request.getParameter("flowId");
        FlowAbilityMonitor flowAbilityMonitor=new FlowAbilityMonitor();
        flowAbilityMonitor.setUserId(user.getUserId());
        flowAbilityMonitor.setRunId(Integer.parseInt(runId));
        flowAbilityMonitor.setUserType(4);
        flowAbilityMonitor.setWorkEnd(lnsfUtil.getSdf().format(new Date()));
        lnsfUtil.setData(flowAbilityMonitor);
        //下一步工作的开始
        String fuzexiaolingdao=lnsfUtil.getWorkNameValue(flowId,runId,"负责校领导");
        Map<String,String> lingdao=lnsfUtil.getIds(fuzexiaolingdao);
        String choosePrcs=prcsId;
        String prcsOpUser=request.getParameter("beginUser");
        String prcsUser=request.getParameter("prcsUser");
        if(!prcsOpUser.equals(lingdao.get("USER_ID"))){//转交到非负责校领导
            String outTime=lnsfUtil.getWorkDeadline(flowId,9);
            Map map=new HashMap();
            map.put("runId",runId);
            map.put("flowPrcs",9);
            map.put("userId",prcsOpUser);
            Map<String,String> rowMap=lnsfUtil.getFlowAbilityMonitorMapper().selectIdByMap(map);
            if(rowMap!=null){
                FlowAbilityMonitor flowAbilityMonitor1=new FlowAbilityMonitor();
                flowAbilityMonitor1.setRunId(Integer.parseInt(runId));
                flowAbilityMonitor1.setUserId(prcsOpUser);
                String deptId=lnsfUtil.getFlowAbilityMonitorMapper().getDeptIdByUserId(prcsOpUser);
                flowAbilityMonitor1.setDeptId(deptId);
                flowAbilityMonitor1.setWorkType(1);
                flowAbilityMonitor1.setUserType(6);
                flowAbilityMonitor1.setDeptType(6);
                flowAbilityMonitor1.setWorkDeadline(outTime);
                flowAbilityMonitor1.setWorkStart(lnsfUtil.getSdf().format(new Date()));
                flowAbilityMonitor1.setWorkTitle("学校领导意见");
                lnsfUtil.setData(flowAbilityMonitor1);
            }
        }

        return null;
    }
}
